package flink

import org.apache.flink.api.common.functions.FlatMapFunction
import org.apache.flink.configuration.Configuration
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}
import org.apache.flink.util.Collector
import org.apache.flink.streaming.api.scala._

object ScalaWordCount {
  def main(args: Array[String]): Unit = {
    //1、创建ENV
//    ExecutionEnvironment.getExecutionEnvironment 自己寻找ENv到底是什么环境
//    ExecutionEnvironment.createLocalEnvironment() 显式创建一个本地的对象
    //本地 有webUi监控页面
//    val env: ExecutionEnvironment = ExecutionEnvironment.createLocalEnvironmentWithWebUI()
//
//    val ds: DataSet[String] = env.readTextFile("data/a.txt")
//    ds.flatMap(_.split(" ")).map((_,1)).groupBy(0).sum(1).print()


    //流
//    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI()
//    //env.setParallelism(1)
//    val ds: DataStream[String] = env.readTextFile("data/a.txt")
//    ds.flatMap(_.split(" ")).map((_,1)).keyBy(0).sum(1).print()
//    env.execute("first stream scala wordcount")


//    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI()
//    val ds: DataStream[String] = env.socketTextStream("192.168.21.160", 6668)
//    ds.flatMap(_.split(" ")).map((_,1)).keyBy(_._1).print()
//    env.execute()

  }
}
